use lazy_static::lazy_static;
use log::info;

pub struct FileMonitor {
    //检测间隔时间-单位秒
    sleep_sec: u64,
}

impl FileMonitor {
    //构造器
    pub fn build() -> FileMonitor {
        // 初始化
        FileMonitor { sleep_sec: 10 }
    }

    //启动检测线程
    pub fn start(&self) {
        let local_ip = local_ipaddress::get().unwrap();
        info!("ip：{}", &local_ip);
        let sleep_sec = self.sleep_sec;
        std::thread::spawn(move || {
            // 这里不用Hot watch了，日志写入非常频繁
            use std::{thread::sleep, time::Duration};

            loop {
                sleep(Duration::from_secs(sleep_sec));
            }
        });
    }
}

lazy_static! {
    pub static ref FILE_MONITOR: FileMonitor = FileMonitor::build();
}
